International aid may take the form of multilateral aid – provided through international bodies such as the UN, or NGOs such as Oxfam – or bilateral aid, which operates on a government-to-government basis. There is considerable debate about whether international aid works, in the sense of reducing poverty and stimulating development.
However, the effectiveness of aid is often diluted by corruption. Aid is invariably channeled through the governments of recipient countries, in which power is often concentrated in the hands of a few politicians and bureaucrats, and the mechanisms of accountability are, at best, poorly developed. This tends to benefit corrupt leaders and elites rather than the people, projects and programs for which it was intended.
Watts, Carl. (2014). Re: Does foreign aid help the developing countries towards development?. Retrieved from: https://www.researchgate.net/post/Does_foreign_aid_help_the_developing_countries_towards_development/5322005ed039b1e7648b459c/citation/download.
The hypothesis that foreign aid can promote growth in developing countries was explored, using panel data series for foreign aid, while accounting for regional differences in Asian, African, Latin American, and the Caribbean countries as well as the differences in income levels, the results of this study also indicate that foreign aid has mixed effects on economic growth in developing countries.
Ekanayake, E. & Chatrna, Dasha. (2010). The effect of foreign aid on economic growth in developing countries. Journal of International Business and Cultural Studies. 3.
This study examines the relationships between foreign aid, institutional structure, and economic performance for 80 countries in Europe, America, Africa, and Asia. It is found that official development assistance and the quality of institutional structure in the sample countries affect economic growth positively.
Hayaloğlu, Pınar. (2023). Foreign Aid, Institutions, and Economic Performance in Developing Countries. Eskişehir Osmangazi Üniversitesi İktisadi ve İdari Bilimler Dergisi. 18. 748-765. 10.17153/oguiibf.1277348.
Algunas librerias y paquetes usados para obtener y descargar los datos
library(tidyverse) # manejo de dataframes
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(reshape2) # para tranfromar data de long a wide
##
## Adjuntando el paquete: 'reshape2'
##
## The following object is masked from 'package:tidyr':
##
## smiths
library(WDI) # libreria para acceder a metadata de banco mundial
library(readxl) # leer archivos de excel
library(readr) # leer archivos csv
library(visdat) # visualizacion de datos como graficos
library(plotly) # graficos
##
## Adjuntando el paquete: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library(purrr) # funcion map
library(plm) # modelos lineales para datos panel
##
## Adjuntando el paquete: 'plm'
##
## The following objects are masked from 'package:dplyr':
##
## between, lag, lead
library(car) # test y utilidades para modelos
## Cargando paquete requerido: carData
##
## Adjuntando el paquete: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
library(htmltools) # para imprimir graficos en html
library(urca) # Unit root test
library(tseries) # Dickey Fuller test (serie estacionaria)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(lmtest) # Pruebas de modelos lineales
## Cargando paquete requerido: zoo
##
## Adjuntando el paquete: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
Datos para paises bajos ingresos sean utilizados, segun clasificación del banco mundial, hay 26 paises de bajos ingresos y 51 de ingresos medios bajos
country_class <- read_excel("CLASS.xlsx")
country_class %>%
filter(!is.na(Region), !is.na(`Income group`)) %>%
group_by(`Income group`) %>%
summarise(countries = n()) %>%
arrange(factor(`Income group`, levels = c('High income', 'Upper middle income', 'Lower middle income', 'Low income')))
Listado de paises a analisar:
my_countries <- country_class %>%
filter(!is.na(Region), `Income group` %in% c('Low income', 'Lower middle income')) %>%
select(Code)
my_countries %>% merge(country_class) %>% select(Code, Economy)
Hacer la respectiva asociacion de nombres iso3c e iso2c
my_countries$iso2c <- WDI_data$country %>%
filter(iso3c %in% my_countries$Code) %>%
.$iso2c
Datos del banco mundial (para ODA y los indices de gobernanza) y el Human Development Reports API son descargados desde scripts de Python. Son almacenados en archivos CSV y luego son cargados aqui:
datos_HDI <- read_csv("datos_python_HDI.csv", col_names = c('Code', 'iso2c', 'indicator', 'year', 'value'),
col_types = list(col_character(), col_character(), col_character(), col_double(), col_double()))
hdi_indicators <- c('hdi') #datos_HDI %>% distinct(indicator) %>% .$indicator
datos_HDI <- datos_HDI %>% filter(indicator %in% hdi_indicators)
oda_indicators <- c(
'DT_ODA_ALLD_CD',
#'DT_ODA_ALLD_KD',
#'DT_ODA_OATL_CD',
#'DT_ODA_OATL_KD',
#'DT_ODA_ODAT_CD',
#'DT_ODA_ODAT_GI_ZS',
#'DT_ODA_ODAT_GN_ZS',
#'DT_ODA_ODAT_KD',
#'DT_ODA_ODAT_MP_ZS',
'DT_ODA_ODAT_PC_ZS'#,
#'DT_ODA_ODAT_XP_ZS'
)
gob_indicators <- c(
'CC_EST',
#'CC_NO_SRC',
#'CC_PER_RNK',
#'CC_PER_RNK_LOWER',
#'CC_PER_RNK_UPPER',
#'CC_STD_ERR',
'GE_EST',
#'GE_NO_SRC',
#'GE_PER_RNK',
#'GE_PER_RNK_LOWER',
#'GE_PER_RNK_UPPER',
#'GE_STD_ERR',
'PV_EST',
# 'PV_NO_SRC',
# 'PV_PER_RNK',
# 'PV_PER_RNK_LOWER',
# 'PV_PER_RNK_UPPER',
# 'PV_STD_ERR',
'RQ_EST',
# 'RQ_NO_SRC',
# 'RQ_PER_RNK',
# 'RQ_PER_RNK_LOWER',
# 'RQ_PER_RNK_UPPER',
# 'RQ_STD_ERR',
'RL_EST',
# 'RL_NO_SRC',
# 'RL_PER_RNK',
# 'RL_PER_RNK_LOWER',
# 'RL_PER_RNK_UPPER',
# 'RL_STD_ERR',
'VA_EST'#,
# 'VA_NO_SRC',
# 'VA_PER_RNK',
# 'VA_PER_RNK_LOWER',
# 'VA_PER_RNK_UPPER',
# 'VA_STD_ERR'
)
gdp_indicators <- c(
# 'NY_ADJ_NNTY_PC_CD',
# 'NY_ADJ_NNTY_PC_KD',
# 'NY_ADJ_NNTY_PC_KD_ZG',
# 'NY_GDP_PCAP_CN',
# 'NY_GDP_PCAP_KN',
'NY_GDP_PCAP_CD',
# 'NY_GDP_PCAP_KD',
# 'NY_GDP_MKTP_KD_ZG',
# 'NY_GDP_DEFL_ZS_AD',
# 'NY_GDP_DEFL_ZS',
# 'NY_GDP_MKTP_CD',
# 'NY_GDP_MKTP_CN',
# 'NY_GDP_MKTP_KN',
# 'NY_GDP_MKTP_KD',
# 'NY_GDP_PCAP_KD_ZG',
# 'NY_GDP_PCAP_PP_KD',
# 'NY_GDP_PCAP_PP_CD',
# 'SL_GDP_PCAP_EM_KD',
'SP_POP_GROW'
)
datos_WB <- data.frame(indicator = character(), iso2c = character(), year = double(), value = double())
suppressWarnings(
for (indicator in c(oda_indicators, gob_indicators, gdp_indicators)) {
datos_WB <- rbind(datos_WB, read_csv(paste("datos_python", indicator, ".csv", sep =''),
col_names = c('indicator', 'iso2c', 'year', 'value'),
col_types = list(col_character(), col_character(), col_double(), col_double())))
}
)
Poverty <- read_excel("GlobalExtremePovertyDollaraDay_Compact.xlsx", sheet = "Data Long Format")
names(Poverty) <- c("ccode", "country", "year", "value")
Poverty[Poverty=="Cape Verde"] <- "Cabo Verde"
Poverty[Poverty=="Congo"] <- "Congo, Rep."
Poverty[Poverty=="Egypt"] <- "Egypt, Arab Rep."
Poverty[Poverty=="Iran"] <- "Iran, Islamic Rep."
Poverty[Poverty=="Kyrgyzstan"] <- "Kyrgyz Republic"
Poverty[Poverty=="Laos"] <- "Lao PDR"
Poverty[Poverty=="Macedonia"] <- "North Macedonia"
Poverty[Poverty=="Russia"] <- "Russian Federation"
Poverty[Poverty=="Slovakia"] <- "Slovak Republic"
Poverty[Poverty=="South Korea"] <- "Korea, Rep."
Poverty[Poverty=="Swaziland"] <- "Eswatini"
Poverty[Poverty=="Syria"] <- "Syrian Arab Republic"
Poverty[Poverty=="The Gambia"] <- "Gambia, The"
Poverty[Poverty=="Turkey"] <- "Turkiye"
Poverty[Poverty=="Venezuela"] <- "Venezuela, RB"
Poverty[Poverty=="Yemen"] <- "Yemen, Rep."
Poverty <- Poverty %>%
filter(year > 1994) %>%
merge(WDI_data$country, all.x = TRUE) %>%
mutate(indicator = 'POV') %>%
merge(my_countries) %>%
select(indicator, iso2c, year, value)
PC_LIB <- read_csv("political-civil-liberties-index.csv")
## Rows: 33643 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Entity, Code
## dbl (2): year, value
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
PC_LIB <- PC_LIB %>%
filter(year > 1994, !is.na(Code)) %>%
merge(my_countries) %>%
mutate(indicator = 'POL.CIV.LIB') %>%
select(indicator, iso2c, year, value)
datos_paper <- rbind(datos_WB, datos_HDI %>% select(indicator, iso2c, year, value), Poverty, PC_LIB) %>%
pivot_wider(names_from = indicator, values_from = value)
datos_paper <- datos_paper %>% mutate(GOV = (CC.EST + GE.EST + PV.EST + RQ.EST + RL.EST + VA.EST) / 6)
datos_paper <- datos_paper %>% arrange(iso2c, year) %>%
mutate(hdi_diff = case_when(iso2c == dplyr::lag(iso2c) ~ hdi - dplyr::lag(hdi), TRUE ~ NA_real_),
NY.GDP.PCAP.CD_diff = case_when(iso2c == dplyr::lag(iso2c) ~ NY.GDP.PCAP.CD - dplyr::lag(NY.GDP.PCAP.CD), TRUE ~ NA_real_),
DT.ODA.ALLD.CD_diff = case_when(iso2c == dplyr::lag(iso2c) ~ DT.ODA.ALLD.CD - dplyr::lag(DT.ODA.ALLD.CD), TRUE ~ NA_real_),
DT.ODA.ODAT.PC.ZS_diff = case_when(iso2c == dplyr::lag(iso2c) ~ DT.ODA.ODAT.PC.ZS - dplyr::lag(DT.ODA.ODAT.PC.ZS), TRUE ~ NA_real_),
GOV_diff = case_when(iso2c == dplyr::lag(iso2c) ~ GOV - dplyr::lag(GOV), TRUE ~ NA_real_),
POV_diff = case_when(iso2c == dplyr::lag(iso2c) ~ POV - dplyr::lag(POV), TRUE ~ NA_real_))
datos_paper <- datos_paper %>% mutate(GOV_GOOD = case_when(GOV >= 0 ~ 1, TRUE ~ 0))
plot_ly(data = datos_paper %>% filter(!is.na(GOV)), y = ~ GOV, type = 'scatter', mode = 'markers') %>%
layout(title = 'Indice promedio de gobernanza', xaxis = list(title = 'Registros'))
datos_paper <- datos_paper %>% mutate(POL.CIV.LIB_GOOD = case_when(POL.CIV.LIB >= 0.5 ~ 1, TRUE ~ 0))
plot_ly(data = datos_paper %>% filter(!is.na(POL.CIV.LIB)), y = ~ POL.CIV.LIB, type = 'scatter', mode = 'markers') %>%
layout(title = 'Indice libertades politicas y civiles', xaxis = list(title = 'Registros'))
datos_paper <- datos_paper %>% mutate(DT.ODA.ALLD.CD_LOG = log(DT.ODA.ALLD.CD))
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `DT.ODA.ALLD.CD_LOG = log(DT.ODA.ALLD.CD)`.
## Caused by warning in `log()`:
## ! Se han producido NaNs
datos_paper <- datos_paper %>% mutate(DT.ODA.ODAT.PC.ZS_2 = DT.ODA.ODAT.PC.ZS ^ 2,
DT.ODA.ALLD.CD_2 = DT.ODA.ALLD.CD ^ 2,
DT.ODA.ALLD.CD_LOG_2 = DT.ODA.ALLD.CD_LOG ^ 2,)
names(datos_paper) <- c('country','year','ODA.ALL','ODA.PC','CC.EST','GE.EST','PV.EST','RQ.EST','RL.EST','VA.EST','GDP.PC','GROW','hdi','POV','POL.CIV.LIB','GOV','hdi_diff','GDP.PC_diff','ODA.ALL_diff','ODA.PC_diff','GOV_diff','POV_diff','GOV_GOOD','POL.CIV.LIB_GOOD','ODA.ALL_LOG','ODA.PC_2','ODA.ALL_2','ODA.ALL_LOG_2')
vis_dat(datos_paper %>% select(ODA.ALL, ODA.PC))
# DT.ODA.OATL.CD and DT.ODA.OATL.KD faltan
# DT.ODA.ODAT.GI.ZS, DT.ODA.ODAT.GN.ZS, DT.ODA.ODAT.MP.ZS and DT.ODA.ODAT.XP.ZS tienen faltas
# Un par de ocurrencias pais-año que faltan datos
vis_dat(datos_paper %>% select(GDP.PC))
# NY.GDP.PCAP.CN, GDP.PC, NY.GDP.MKTP.CD, NY.GDP.MKTP.CN son buenos candidatos para usar como variables,
# 'SY'falta PIB per Capita en 2022, 2023 sin datos algunos paises
vis_dat(datos_paper %>% arrange(year) %>% select(all_of(gsub("_", ".", gob_indicators))))
# Datos del 2000 para atras tienen espacios faltantes
vis_dat(datos_paper %>% arrange(year) %>% select(all_of(hdi_indicators)))
# abr, co2_prod, le, le_f, le_m, mmr son las pocas categorias sin datos faltantes
# hdi faltante en multiples ocaciones
vis_dat(datos_paper %>% arrange(country) %>% select(GROW))
vis_dat(datos_paper %>% arrange(year, country) %>% select(POV))
# 'AF', 'CD', 'CI', 'DJ', 'KH', 'LR', 'MR', 'PG', 'ST', 'TJ', 'UZ', 'VN', 'WS' no tienen datos de esta variable
# Porcentaje de personas por debajo de la linea de extrema pobreza (Dollar a day)
vis_dat(datos_paper %>% arrange(country) %>% select(POL.CIV.LIB))
# KI MR SD WS son paises sin datos para estos años
temp <- datos_paper %>%
filter(!year < 2002, !year > 2022, !country %in% c('SS')) %>%
merge(my_countries) %>%
merge(country_class) %>%
group_by(`Income group`) %>%
summarise('2002 - 2022' = sum(ODA.ALL))
temp
plot_ly(temp %>%
mutate(`Income group` = case_when(`Income group` == 'Low income' ~ 'Ingresos Bajos',
`Income group` == 'Lower middle income' ~ 'Ingresos Medios-bajos')),
labels = ~`Income group`, values = ~`2002 - 2022`, type = 'pie', textinfo = 'label+percent') %>%
layout(title = 'Asistencia Oficial para el Desarrollo recibida total 2002 - 2022',
plot_bgcolor = "#e5ecf6")
########################################################################
temp <- datos_paper %>%
mutate(y_range = case_when(year < 2007 ~ '2002 - 2006',
year < 2012 ~ '2007 - 2011',
year < 2017 ~ '2012 - 2016',
TRUE ~ '2017 - 2022')) %>%
filter(!year < 2002, !year > 2022, !country %in% c('SS')) %>%
merge(my_countries) %>%
merge(country_class) %>%
group_by(`Income group`, y_range) %>%
summarise(sum=sum(ODA.ALL), .groups = "drop")
temp %>% pivot_wider(names_from = y_range, values_from = sum)
plot_ly(temp %>% pivot_wider(names_from = `Income group`, values_from = sum),
x = ~y_range, y = ~`Lower middle income`, name = 'Ingresos Medios-bajos', type = 'bar') %>%
add_trace(y = ~`Low income`, name = 'Ingresos Bajos') %>%
layout(title = 'Asistencia Oficial para el Desarrollo recibida total',
yaxis = list(title = 'Dolares Actuales'), xaxis = list(title = 'Periodo'), barmode = 'group')
########################################################################
temp <- datos_paper %>%
filter(!year < 2002, !year > 2022, !country %in% c('SS')) %>%
merge(my_countries) %>%
merge(country_class) %>%
group_by(Region) %>%
summarise('2002 - 2022' = sum(ODA.ALL))
temp
plot_ly(temp, labels = ~Region, values = ~`2002 - 2022`, type = 'pie', textinfo = 'label+percent') %>%
layout(title = 'Asistencia Oficial para el Desarrollo recibida total 2002 - 2022',
plot_bgcolor = "#e5ecf6")
########################################################################
temp <- datos_paper %>%
mutate(y_range = case_when(year < 2007 ~ '2002 - 2006',
year < 2012 ~ '2007 - 2011',
year < 2017 ~ '2012 - 2016',
TRUE ~ '2017 - 2022')) %>%
filter(!year < 2002, !year > 2022, !country %in% c('SS')) %>%
merge(my_countries) %>%
merge(country_class) %>%
group_by(Region, y_range) %>%
summarise(sum=sum(ODA.ALL), .groups = "drop")
temp %>%
pivot_wider(names_from = y_range, values_from = sum)
plot_ly(temp %>% pivot_wider(names_from = Region, values_from = sum),
x = ~y_range, y = ~`Sub-Saharan Africa`, name = 'Sub-Saharan Africa', type = 'bar') %>%
add_trace(y = ~`East Asia & Pacific`, name = 'East Asia & Pacific') %>%
add_trace(y = ~`Middle East & North Africa`, name = 'Middle East & North Africa') %>%
add_trace(y = ~`South Asia`, name = 'South Asia') %>%
add_trace(y = ~`Latin America & Caribbean`, name = 'Latin America & Caribbean') %>%
add_trace(y = ~`Europe & Central Asia`, name = 'Europe & Central Asia') %>%
layout(title = 'Asistencia Oficial para el Desarrollo recibida total',
yaxis = list(title = 'Dolares Actuales'), xaxis = list(title = 'Periodo'), barmode = 'group')
########################################################################
temp <- datos_paper %>%
filter(!year < 2002, !year > 2022, !country %in% c('SS', 'KP')) %>%
merge(my_countries) %>%
merge(country_class)
suppressWarnings(
plot_ly(temp %>% filter(year %in% c(2002, 2012, 2022)), x = ~year, y = ~hdi, color = ~`Income group`, type = "box") %>%
layout(title = 'Indice de desarrollo Humano en paises de Ingresos Bajos e Ingresos Medios-bajos',
boxmode = "group")
)
## Warning: Ignoring 693 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning: 'layout' objects don't have these attributes: 'boxmode'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'
suppressWarnings(
plot_ly(temp %>% filter(year %in% c(2002, 2012, 2022)), x = ~year, y = ~hdi, color = ~Region, type = "box") %>%
layout(title = 'Indice de desarrollo Humano segun Region', boxmode = "group")
)
## Warning: Ignoring 693 observations
## Warning: 'layout' objects don't have these attributes: 'boxmode'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'
########################################################################
suppressWarnings(
plot_ly(temp %>% filter(year %in% c(2002, 2012, 2022)), x = ~year, y = ~GOV, color = ~`Income group`, type = "box") %>%
layout(title = 'Indice de gobernanza en paises de Ingresos Bajos e Ingresos Medios-bajos', boxmode = "group")
)
## Warning: Ignoring 308 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning: 'layout' objects don't have these attributes: 'boxmode'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'
suppressWarnings(
plot_ly(temp %>% filter(year %in% c(2002, 2012, 2022)), x = ~year, y = ~GOV, color = ~Region, type = "box") %>%
layout(title = 'Indice de gobernanza segun Region', boxmode = "group")
)
## Warning: Ignoring 308 observations
## Warning: 'layout' objects don't have these attributes: 'boxmode'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'
# variables de etiqueta
ve <- c('country', 'year')
# variables depndientes
vd <- c('hdi')
# 'hdi', 'hdi_diff', 'GDP.PC', 'GDP.PC_diff', 'POV', 'POV_diff',
# variables independientes
vi <- c('ODA.PC')
# 'ODA.PC', 'ODA.ALL', 'ODA.ALL_diff', 'ODA.PC_diff',
# 'ODA.ALL_LOG'
# variables de control
vc <- c('GOV', 'GDP.PC')
# 'GROW', 'CC.EST', 'GE.EST', 'PV.EST', 'RQ.EST', 'RL.EST', 'VA.EST', 'GOV', 'GOV_diff'
# 'GDP.PC', 'POL.CIV.LIB', 'ODA.PC_2', 'ODA.ALL_2', 'ODA.ALL_LOG_2'
# variables interactivas
vint <- c('GOV_GOOD') # 'GOV_GOOD', 'POL.CIV.LIB_GOOD'
# paises sin datos
delete_c <- c('SS', 'BT', 'ER', 'GW', 'KP', 'LB', 'NG', 'PS', 'SO', 'VU', 'FM', 'KI', 'SB', 'SY')
#, 'KI', 'MR', 'SD', 'WS' Si se usa POL.CIV.LIB
#, 'AF', 'CD', 'CI', 'DJ', 'KH', 'LR', 'MR', 'PG', 'ST', 'TJ', 'TL', 'UZ', 'VN', 'WS', 'ZW' Si se usa POV
#, 'LK', 'PH' Si se usa ODA.ALL_LOG
# años sin datos
first_y <- 2002
last_y <- 2022 # 2018 si se usa POV
f <- paste(vd, '~', case_when(length(vint) > 0 ~ paste(vi, vint, sep = '*'), TRUE ~ vi), '+', paste(vc, collapse = ' + '))
datos_model <- datos_paper %>%
filter(!country %in% delete_c, !year < first_y, !year > last_y) %>%
select(all_of(c(ve, vd, vi, vc, vint)))
datos_model
vis_dat(datos_model)
Se revisara las relaciones entre las variables graficamente
my_plot = list()
for (vd_ in vd) {
for (vi_ in c(vi, vc)){
fit <- lm(paste(vd_, '~', vi_) ,data = datos_model)
my_plot[[paste(vd_,vi_)]] <- plot_ly(x = datos_model[[vi_]],
y = datos_model[[vd_]],
type = 'scatter',
mode = 'markers',
name = vi_) %>%
add_lines(x = datos_model[[vi_]], fitted(fit), name = paste("trace", vi_))
}
}
subplot(my_plot, nrows = 2, margin = 0.05) %>% layout(title = vd)
model_ols <- lm(f, data=datos_model)
model_fe <- plm(f, data=datos_model, index = ve, model = "within")
model_re <- plm(f, data=datos_model, index = ve, model = "random")
print(f)
## [1] "hdi ~ ODA.PC*GOV_GOOD + GOV + GDP.PC"
summary(model_ols)
##
## Call:
## lm(formula = f, data = datos_model)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.228225 -0.045678 -0.000837 0.042303 0.187854
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.615e-01 6.501e-03 70.999 < 2e-16 ***
## ODA.PC -5.542e-05 3.761e-05 -1.474 0.141
## GOV_GOOD 2.180e-02 1.743e-02 1.251 0.211
## GOV 2.711e-02 5.106e-03 5.310 1.28e-07 ***
## GDP.PC 6.679e-05 2.142e-06 31.189 < 2e-16 ***
## ODA.PC:GOV_GOOD -5.310e-05 6.136e-05 -0.865 0.387
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.07307 on 1317 degrees of freedom
## Multiple R-squared: 0.5184, Adjusted R-squared: 0.5166
## F-statistic: 283.6 on 5 and 1317 DF, p-value: < 2.2e-16
residualPlots(model_ols)
## Test stat Pr(>|Test stat|)
## ODA.PC 3.2559 0.001159 **
## GOV_GOOD -0.5382 0.590510
## GOV -2.5201 0.011851 *
## GDP.PC -11.5520 < 2.2e-16 ***
## Tukey test -9.5593 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(model_ols)
vif(model_ols)
## there are higher-order terms (interactions) in this model
## consider setting type = 'predictor'; see ?vif
## ODA.PC GOV_GOOD GOV GDP.PC ODA.PC:GOV_GOOD
## 2.359799 3.312239 1.504980 1.261946 4.860636
print(f)
## [1] "hdi ~ ODA.PC*GOV_GOOD + GOV + GDP.PC"
summary(model_fe)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = f, data = datos_model, model = "within", index = ve)
##
## Balanced Panel: n = 63, T = 21, N = 1323
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.1031137 -0.0175508 0.0008701 0.0187271 0.1228234
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## ODA.PC 1.0963e-04 2.6502e-05 4.1365 3.761e-05 ***
## GOV_GOOD 2.9530e-02 9.1944e-03 3.2117 0.0013530 **
## GOV 1.7943e-02 5.1958e-03 3.4533 0.0005722 ***
## GDP.PC 4.2978e-05 1.5088e-06 28.4849 < 2.2e-16 ***
## ODA.PC:GOV_GOOD -1.9176e-04 3.7722e-05 -5.0835 4.268e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 1.8892
## Residual Sum of Squares: 1.0588
## R-Squared: 0.43953
## Adj. R-Squared: 0.40961
## F-statistic: 196.837 on 5 and 1255 DF, p-value: < 2.22e-16
#summary(lm(paste(f, '+ country'), data=datos_model))
print(f)
## [1] "hdi ~ ODA.PC*GOV_GOOD + GOV + GDP.PC"
summary(model_re)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = f, data = datos_model, model = "random", index = ve)
##
## Balanced Panel: n = 63, T = 21, N = 1323
##
## Effects:
## var std.dev share
## idiosyncratic 0.0008437 0.0290465 0.153
## individual 0.0046719 0.0683513 0.847
## theta: 0.9077
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.1010862 -0.0166077 0.0026172 0.0192163 0.1186122
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 4.7786e-01 9.8844e-03 48.3449 < 2.2e-16 ***
## ODA.PC 1.0461e-04 2.6322e-05 3.9744 7.055e-05 ***
## GOV_GOOD 3.0137e-02 9.1489e-03 3.2941 0.0009875 ***
## GOV 1.9511e-02 5.0565e-03 3.8587 0.0001140 ***
## GDP.PC 4.3688e-05 1.4988e-06 29.1486 < 2.2e-16 ***
## ODA.PC:GOV_GOOD -1.8419e-04 3.7495e-05 -4.9124 8.996e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 1.9976
## Residual Sum of Squares: 1.1179
## R-Squared: 0.44036
## Adj. R-Squared: 0.43824
## Chisq: 1036.31 on 5 DF, p-value: < 2.22e-16
print(f)
## [1] "hdi ~ ODA.PC*GOV_GOOD + GOV + GDP.PC"
phtest(model_fe, model_re)
##
## Hausman Test
##
## data: f
## chisq = 17.808, df = 5, p-value = 0.003196
## alternative hypothesis: one model is inconsistent
df=ur.df(datos_model %>% filter(country == 'AO') %>% .[[vi]],type="none",lags=0)
df
##
## ###############################################################
## # Augmented Dickey-Fuller Test Unit Root / Cointegration Test #
## ###############################################################
##
## The value of the test statistic is: -1.8892
print('La serie es estacionaria si el valor del estadistico de prueba excede estos valores al 99%, 95% y 90% respectivamente')
## [1] "La serie es estacionaria si el valor del estadistico de prueba excede estos valores al 99%, 95% y 90% respectivamente"
qnorm(c(.01,.05,.1)/2)
## [1] -2.575829 -1.959964 -1.644854
adf.test(datos_model[[vi]], k= 0)
## Warning in adf.test(datos_model[[vi]], k = 0): p-value smaller than printed
## p-value
##
## Augmented Dickey-Fuller Test
##
## data: datos_model[[vi]]
## Dickey-Fuller = -10.182, Lag order = 0, p-value = 0.01
## alternative hypothesis: stationary
y <- data.frame(split(datos_model[[vi]], datos_model$country)) # individuals in columns
purtest(y, pmax = 4, exo = "intercept", test = "madwu")
##
## Maddala-Wu Unit-Root Test (ex. var.: Individual Intercepts)
##
## data: y
## chisq = 359.5, df = 126, p-value < 2.2e-16
## alternative hypothesis: stationarity
pcdtest(model_fe, test = c("lm"))
##
## Breusch-Pagan LM test for cross-sectional dependence in panels
##
## data: hdi ~ ODA.PC * GOV_GOOD + GOV + GDP.PC
## chisq = 20259, df = 1953, p-value < 2.2e-16
## alternative hypothesis: cross-sectional dependence
pcdtest(model_fe, test = c("cd"))
##
## Pesaran CD test for cross-sectional dependence in panels
##
## data: hdi ~ ODA.PC * GOV_GOOD + GOV + GDP.PC
## z = 67.307, p-value < 2.2e-16
## alternative hypothesis: cross-sectional dependence
pbgtest(model_fe)
##
## Breusch-Godfrey/Wooldridge test for serial correlation in panel models
##
## data: f
## chisq = 924.45, df = 21, p-value < 2.2e-16
## alternative hypothesis: serial correlation in idiosyncratic errors
bptest(hdi ~ ODA.PC*GOV_GOOD + GDP.PC + GOV, data = datos_model, studentize = F)
##
## Breusch-Pagan test
##
## data: hdi ~ ODA.PC * GOV_GOOD + GDP.PC + GOV
## BP = 24.74, df = 5, p-value = 0.0001564
print('alternative hypothesis: Heteroscedasticidad')
## [1] "alternative hypothesis: Heteroscedasticidad"
coeftest(model_fe)
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## ODA.PC 1.0963e-04 2.6502e-05 4.1365 3.761e-05 ***
## GOV_GOOD 2.9530e-02 9.1944e-03 3.2117 0.0013530 **
## GOV 1.7943e-02 5.1958e-03 3.4533 0.0005722 ***
## GDP.PC 4.2978e-05 1.5088e-06 28.4849 < 2.2e-16 ***
## ODA.PC:GOV_GOOD -1.9176e-04 3.7722e-05 -5.0835 4.268e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coeftest(model_fe, vcovHC(model_fe, type = "HC3"))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## ODA.PC 1.0963e-04 6.1533e-05 1.7816 0.075057 .
## GOV_GOOD 2.9530e-02 1.5307e-02 1.9292 0.053929 .
## GOV 1.7943e-02 1.6301e-02 1.1007 0.271233
## GDP.PC 4.2978e-05 4.7787e-06 8.9935 < 2.2e-16 ***
## ODA.PC:GOV_GOOD -1.9176e-04 6.7946e-05 -2.8222 0.004844 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
save(f, delete_c, first_y, last_y, my_plot, model_ols, model_fe, model_re, file = "hdi_ODA.PCGOV_GOOD_GOV_GDP.PC.RData")
#load("hdi_ODA.PCGOV_GOOD_GOV_GDP.PC_GROW.RData")
#load("hdi_ODA.PCGOV_GOOD_GOV_GDP.PC.RData")
#load("GDP.PC_ODA.PCGOV_GOOD_GOV_GROW.RData")
#load("POV_ODA.PCGOV_GOOD_GOV_GDP.PC_GROW.RData")